<?php

class top extends spController {

    function __construct() {
        parent::__construct(); 
    }

    function __error($code,$msg="") {
        if($msg==""){
            switch ($code) {
                case 0:
                    $msg = "succeed!";
                    break;
                case 1:
                    $msg = "lose param!";
                    break;
                case 2:
                    $msg = "no result!";
                    break;
                case 3:
                    $msg = 'failed!';           
                    break;
                default:
                    $msg = "error!no reason!";
                    break;
            }            
        }     
        echo json_encode(array('errcode'=>$code,'errmsg'=>$msg));
        exit;
    }
    /*除登录页都要验证session*/
    function check_session(){//检查SESSION        
        $user_name = $_SESSION['username'];
        $pass = $_SESSION['pwd'];
       if( $user_name=="" || $pass==""){
           return false;
       }else {

            $user = spClass("m_user");
            $condition = array('username' => $user_name,);
            $result = $user->find($condition, '', 'pwd');
            $che_pass = $result['pwd'];
            if ($che_pass != $pass) {
                return false;
            } else {
                //超时自动退出
                $lifeTime = 3600 * 24 * 30;
                //将sessionId保存1个月。
                setcookie(session_name(), session_id(), time() + $lifeTime, "/");

                return true;
            }
        }
    }

}